# -*- coding: utf-8 -*-
"""
Created on Tue Dec  6 15:20:14 2022

@author: DELL
"""

import time
import numpy as np
import serial
import re
firstPlotString="respiration start"+"\r\n(.*?)"+"respiration stop"

ser=serial.Serial()
ser.baudrate    = 115200
ser.timeout     = 1
ser.port="COM2"
ser.open()                     
time.sleep(0.1)
ser.reset_input_buffer()
#print("open com port successfully")
recvStr=ser.read_all().decode('ascii', 'ignore')
if len(recvStr):
    print(recvStr)
    dataStr=re.findall(firstPlotString,recvStr,re.S)
    print(dataStr)
    dataArray=np.array(dataStr[0].split("\r\n"))
    b=dataArray[:-1]
    b=b.astype(float)
    print(b)
ser.close()    
